This invention relates to writing of computer programs in source code and more particularly to a process for automatically translating programs written using a procedural programming language into programs written using an object oriented programming language.
In computer programs written using a procedural language, the programmer specifies an explicit sequences of steps to follow to produce a result. Variables, first defined in the program, are used in the steps of the procedural language. The drawbacks of a procedural language is that the code produced is very specific to the physical implementation of the data processed and very specific to the view the user has of this data. This has a huge impact on the user""s workload in maintaining these programs and further limits program reuse.
Object oriented (OO) languages have been created to overcome the drawbacks of procedural languages. The starting point is to build a user""s model by creating xe2x80x9cobjects.xe2x80x9d These objects are xe2x80x9cdata structuresxe2x80x9d encapsulated with a set or routines called xe2x80x9cmethodsxe2x80x9d which operate on the data. An Object has xe2x80x9cattributes.xe2x80x9d An example would be the attribute employee number (5 digits) of an employee object. An access method could be xe2x80x9cget employee.xe2x80x9d Operations on the data can only be performed via these methods. Objects having similar behavior (this is the observable effect of performing a method) can be grouped in the same xe2x80x9cclass.xe2x80x9d A class is an object definition describing a category of objects and an object is an instance of a class. Classes are arranged in a class hierarchy: it must be possible to create classes and subclasses and let objects in a subclass xe2x80x9cinheritxe2x80x9d eveything from their super classes. In an object-oriented developed application, objects use the services of other objects, which in turn use the service of other objects and so on.
In programming using object oriented languages, a programmer""s first task is to design a model of basic business objects along with how they interact with each other in order to provide the functions which are requested by the end user.
Because the model is independent of the location of the data or the data base structure, the main advantage of OO languages is the reusability of code. Reusable code in an OO system are xe2x80x9cblack boxes,xe2x80x9d the only thing that needs to be understood when using the code is their interfaces, not their implementation. Well designed classes and the structure of the class hierarchy will be a major factor determining the reusability of objects. Other advantages of the OO languages are the correctness and the maintainability of the code. OO software development cuts cost, shortens development time, and lowers maintenance cost.
For all the advantages of OO programming languages, many existing applications or part of applications written in procedural languages need to be translated into an OO language. When done manually this represents a huge amount of work as the first step will consist first in designing the data structure (objects, classes) corresponding to the application executed by the procedural language code. The design phase cannot be accomplished from the unique procedural code but from an initial functional analysis of the application which is not always available.
Known translators of the prior art first perform a lexical analysis of the input source code. The stream of characters making up the source code is read one at a time and grouped into tokens, word-like pieces such as keywords, identifiers, and punctuation. The translators of the prior art then perform the syntactical analysis, discovering the structure of strings which is described by a grammar. VB2Java is such a translator, which translates Visual Basic to Java. The common language translators working at lexical and syntactical level leave a high percentage of manual rework to complete the translation. With prior art translators, each variable of the procedural language code is mapped to a class attribute, the result of the translation being one single class per source code program The resulting code, even if it can be compiled by a OO language compiler, provides a simplified OO model and thus limits the capability of code reuse and flexibility. This is particularly the case when the initial language to be translated has higher semantic capabilities. The meaning of the language is given by its semantics. The study of meaning and changes of meaning is performed by a semantic analysis. Current translators knowing only the language syntactical grammar fail in translating towards languages having more complex semantics. This implies that when the target language is an OO language, the objects resulting to higher levels of semantics are not identified, meaning that there is no code reuse and thus benefit to translating into an OO language.
In brief, it is an object of the invention to provide a method to translate a procedural source code to Object Oriented (OO) source code characterized in that it comprises the steps of:
1. defining the patterns of the procedural source code according to the semantic grammar of said procedural language;
2. performing a lexical and syntactical reading of the procedural source code and determining the sequences of instructions in procedural source code corresponding to the identified patterns;
3. identifying new objects, attributes, access methods to objects or access methods to attributes identified in said sequences and storing them in an Object Dictionary; and
4. for each said sequence of source code, if not yet existing, creating a new type of OO classes, and new OO source code classes using the objects of said Object Dictionary.
With the translator of the invention, once the source code programs of an application are translated a complete object model is also generated; it allows reuse of code, use of distributed architecture and flexibility.